/**
 * 菜单修改.
 */
var fnt_icons_categorized = {
				'Web Application Icons' : ["icon-mail", "icon-mail-alt", "icon-th-large", "icon-th", "icon-th-list", "icon-help-circled", "icon-info-circled", "icon-info", "icon-home", "icon-link", "icon-unlink", "icon-link-ext", "icon-link-ext-alt", "icon-attach", "icon-tag", "icon-tags", "icon-bookmark", "icon-bookmark-empty", "icon-download", "icon-upload", "icon-download-cloud", "icon-upload-cloud", "icon-reply", "icon-reply-all"],
				'Form Control Icons' : ["icon-search", "icon-ok", "icon-ok-circled", "icon-ok-circled2", "icon-ok-squared", "icon-cancel", "icon-cancel-circled", "icon-cancel-circled2", "icon-plus", "icon-plus-circled", "icon-plus-squared", "icon-plus-squared-small", "icon-minus", "icon-minus-circled", "icon-minus-squared", "icon-minus-squared-alt", "icon-minus-squared-small", "icon-quote-right", "icon-code", "icon-comment-empty", "icon-chat-empty"],
				'Media Icons' : ["icon-video", "icon-videocam", "icon-picture", "icon-camera", "icon-camera-alt", "icon-export", "icon-export-alt", "icon-pencil", "icon-pencil-squared", "icon-edit", "icon-print"],
				'Popular Icons' : ["icon-heart", "icon-heart-empty", "icon-star", "icon-star-empty", "icon-star-half", "icon-star-half-alt", "icon-user", "icon-users", "icon-male", "icon-female", "icon-forward", "icon-quote-left", "icon-retweet", "icon-keyboard", "icon-gamepad", "icon-comment", "icon-chat"],
				'Others' : ["icon-music", "icon-help", "icon-lock", "icon-lock-open", "icon-lock-open-alt", "icon-pin", "icon-eye", "icon-eye-off", "icon-flag", "icon-flag-empty", "icon-flag-checkered", "icon-thumbs-up", "icon-thumbs-down", "icon-thumbs-up-alt", "icon-thumbs-down-alt", "icon-bell", "icon-bell-alt"]
			};  
$(document).ready(function() {
    //初始化菜单树
   // initTreeMenu();
    $("#spinner").spinner();
    $('#icon').fontIconPicker({
	       source: fnt_icons_categorized,
	        theme: 'fip-bootstrap'
	    });
	});
// 初始化左侧菜单
function initTreeMenu() {
    var searchURL = basePath + "/ajaxGetUserMenuList.shtml";
    $.ajax({
        url: searchURL,
        type: "post",
        contentType: "application/json; charset=UTF-8",
        dataType: "json",
        success: function(jsonResult) {
            if (jsonResult.success) {
                loadTreeMenu(jsonResult.data);
            } else {
                // handleAjaxResponseError(jsonResult);
            }
        },
        // 请求失败
        error: function(xhr) {
            // loadFinished("dataTable");
            // handleAjaxRequestError(xhr);
        }

    });
}
// 菜单数据加载.
function loadTreeMenu(data) {
	data[0].state="selected : true";
    var menutree = "<ul>";
    for (var i = 0; i < data.length; i++) {
        if (data[i].parentId == '0' && data[i].isShow == '1') {
            menutree += " <li class='jstree-node  jstree-open' id=" + data[i].id + ">" + data[i].name;
            for (var j = 0; j < data.length; j++) {
                menutree += "  <ul>";
                if (data[j].isShow == '1' && data[j].parentId == data[i].id) {

                    menutree += "  <li data-jstree='{ 'icon' : 'fa fa-briefcase icon-state-success ' }' id=" + data[j].id + ">" + data[j].name + "</li>";
                }
                menutree += "  </ul>";
            }
            menutree += " </li >";
        }
    }
    menutree += " </ul>";
    $("#roleTree").html(menutree);
    // 默认展开所有节点
    $('#roleTree').bind("loaded.jstree",
    function(e, data) {
        data.inst.open_all("-1"); // -1 opens all nodes in the Container
    });
    ref=$('#roleTree').jstree({
    	"ui":{ 
    		"initially_select":["1"] 
    		}, 
    		"core" : { 
    		"initially_open" : ["1", "2"] 
    		}, 
    });
}
function updateMenu(){
	 var searchURL = basePath + "/sys/sysmenu/ajaxUpdate.shtml";
	    $.ajax({
	        url: searchURL,
	        type: "post",
	        data:getUpdateCondition(),
	        contentType: "application/json; charset=UTF-8",
	        dataType: "json",
	        success: function(jsonResult) {
	            if (jsonResult.success) {
	            	bootbox.alert("修改成功!");    
	            	window.location.href=basePath + "/sys/sysmenu/list.shtml";
	            } else {
	                // handleAjaxResponseError(jsonResult);
	            }
	        },
	        // 请求失败
	        error: function(xhr) {
	            // loadFinished("dataTable");
	            // handleAjaxRequestError(xhr);
	        }

	    });
	
}
function getUpdateCondition() {
	var data=$('#updForm').serializeObject();
	return data;
}
